package lol.clann.minecraft.springboot.bukkit.utils;

import lombok.Getter;

import javax.annotation.Nullable;

/**
 *
 * @author pyz
 * @date 2019/5/2 10:27 PM
 */
public class NMSClasses {
    @Getter
    private static final int version = BukkitUtils.getBukkitVersionNumber();

    @Getter
    private static final Class MinecraftServer;

    @Getter
    private static final Class IBlockAccess;
    @Getter
    private static final Class World;
    @Getter
    private static final Class WorldServer;

    @Getter
    private static final Class WorldProvider;

    @Getter
    private static final Class Chunk;
    @Getter
    private static final Class EntityPlayer;
    @Getter
    private static final Class IInventory;
    @Getter
    private static final Class Entity;
    @Getter
    private static final Class EntityLiving;
    @Getter
    private static final Class EntityHuman;
    @Getter
    private static final Class PlayerInteractManager;
    @Getter
    private static final Class PlayerConnection;
    @Getter
    private static final Class NetworkManager;
    @Getter
    private static final Class GameProfile;
    @Getter
    private static final Class Channel;
    @Getter
    private static final Class TileEntity;
    @Getter
    private static final Class Packet;
    @Getter
    private static final Class NBTBase;
    @Getter
    private static final Class NBTTagByte;
    @Getter
    private static final Class NBTTagByteArray;
    @Getter
    private static final Class NBTTagShort;
    @Getter
    private static final Class NBTTagInt;
    @Getter
    private static final Class NBTTagIntArray;
    @Getter
    private static final Class NBTTagLong;
    @Nullable
    @Getter
    private static final Class NBTTagLongArray;
    @Getter
    private static final Class NBTTagFloat;
    @Getter
    private static final Class NBTTagDouble;
    @Getter
    private static final Class NBTTagString;
    @Getter
    private static final Class NBTTagList;
    @Getter
    private static final Class NBTTagCompound;
    @Getter
    private static final Class NBTReadLimiter;
    @Getter
    private static final Class NBTCompressedStreamTools;
    @Getter
    private static final Class ItemStack;
    @Getter
    private static final Class EntityItem;

    @Nullable
    @Getter
    private static final Class BlockPosition;
    @Getter
    private static final Class BlockFluids;

    @Getter
    private static final Class ChatComponentText;
    @Getter
    private static final Class ChatSerializer;

    @Getter
    private static final Class PacketPlayInUseEntity;
    @Getter
    private static final Class IChatBaseComponent;
    @Getter
    private static final Class PacketPlayOutBlockChange;
    @Getter
    private static final Class PacketPlayOutHeldItemSlot;
    @Getter
    private static final Class PacketPlayOutChat;

    @Nullable
    @Getter
    private static final Class ChatMessageType;

    @Getter
    private static final Class Vec3D;

    @Getter
    private static final Class MovingObjectPosition;
    @Nullable
    @Getter
    private static final Class MovingObjectPositionEntity;
    @Nullable
    @Getter
    private static final Class MovingObjectPositionBlock;
    @Nullable
    @Getter
    private static final Class RayTrace;
    @Nullable
    @Getter
    private static final Class BlockCollisionOption;

    /**
     * 1.8+
     */
    @Nullable
    @Getter
    private static final Class EnumDirection;

    @Getter
    private static final Class EnumMovingObjectType;

    @Getter
    private static final Class AxisAlignedBB;
    @Getter
    private static final Class LocaleLanguage;
    /**
     * 1.19+
     */
    @Nullable
    @Getter
    private static final Class DimensionManager;
    /**
     * 1.13+
     */
    @Nullable
    @Getter
    private static final Class FluidCollisionOption;
    @Getter
    private static final Class ChatMessage;

    static {
        try {
            ChatMessageType = version < 11200 ? null : NMSReflectUtils.forName("{nms}.ChatMessageType");

            MinecraftServer = NMSReflectUtils.forName("{nms}.MinecraftServer");
            IBlockAccess = NMSReflectUtils.forName("{nms}.IBlockAccess");
            World = NMSReflectUtils.forName("{nms}.World");
            WorldServer = NMSReflectUtils.forName("{nms}.WorldServer");
            WorldProvider = NMSReflectUtils.forName("{nms}.WorldProvider");
            Chunk = NMSReflectUtils.forName("{nms}.Chunk");
            TileEntity = NMSReflectUtils.forName("{nms}.TileEntity");
            Entity = NMSReflectUtils.forName("{nms}.Entity");
            EntityLiving = NMSReflectUtils.forName("{nms}.EntityLiving");
            EntityHuman = NMSReflectUtils.forName("{nms}.EntityHuman");

            EntityPlayer = NMSReflectUtils.forName("{nms}.EntityPlayer");

            IInventory = NMSReflectUtils.forName("{nms}.IInventory");

            NBTBase = NMSReflectUtils.forName("{nms}.NBTBase");
            NBTTagByte = NMSReflectUtils.forName("{nms}.NBTTagByte");
            NBTTagByteArray = NMSReflectUtils.forName("{nms}.NBTTagByteArray");
            NBTTagShort = NMSReflectUtils.forName("{nms}.NBTTagShort");
            NBTTagInt = NMSReflectUtils.forName("{nms}.NBTTagInt");
            NBTTagIntArray = NMSReflectUtils.forName("{nms}.NBTTagIntArray");
            NBTTagLong = NMSReflectUtils.forName("{nms}.NBTTagLong");
            NBTTagFloat = NMSReflectUtils.forName("{nms}.NBTTagFloat");
            NBTTagDouble = NMSReflectUtils.forName("{nms}.NBTTagDouble");
            NBTTagString = NMSReflectUtils.forName("{nms}.NBTTagString");
            NBTTagList = NMSReflectUtils.forName("{nms}.NBTTagList");
            NBTTagCompound = NMSReflectUtils.forName("{nms}.NBTTagCompound");
            NBTTagLongArray = version < 11200 ? null : NMSReflectUtils.forName("{nms}.NBTTagLongArray");
            NBTReadLimiter = NMSReflectUtils.forName("{nms}.NBTReadLimiter");
            NBTCompressedStreamTools = NMSReflectUtils.forName("{nms}.NBTCompressedStreamTools");
            ItemStack = NMSReflectUtils.forName("{nms}.ItemStack");
            EntityItem = NMSReflectUtils.forName("{nms}.EntityItem");
            BlockPosition = version < 10800 ? null : NMSReflectUtils.forName("{nms}.BlockPosition");

            BlockFluids = NMSReflectUtils.forName("{nms}.BlockFluids");

//          数据包
            Packet = NMSReflectUtils.forName("{nms}.Packet");
            PacketPlayInUseEntity = NMSReflectUtils.forName("{nms}.PacketPlayInUseEntity");
            PacketPlayOutBlockChange = NMSReflectUtils.forName("{nms}.PacketPlayOutBlockChange");
            PacketPlayOutHeldItemSlot = NMSReflectUtils.forName("{nms}.PacketPlayOutHeldItemSlot");
            PacketPlayOutChat = NMSReflectUtils.forName("{nms}.PacketPlayOutChat");

            IChatBaseComponent = NMSReflectUtils.forName("{nms}.IChatBaseComponent");
//           1.7  1.8+
            ChatSerializer = NMSReflectUtils.forName("{nms}.ChatSerializer", "{nms}.IChatBaseComponent$ChatSerializer");
            ChatComponentText = NMSReflectUtils.forName("{nms}.ChatComponentText");


            PlayerInteractManager = NMSReflectUtils.forName("{nms}.PlayerInteractManager");
            PlayerConnection = NMSReflectUtils.forName("{nms}.PlayerConnection");
            NetworkManager = NMSReflectUtils.forName("{nms}.NetworkManager");
            GameProfile = NMSReflectUtils.forName("com.mojang.authlib.GameProfile");
            Channel = NMSReflectUtils.forName("io.netty.channel.Channel");

            Vec3D = NMSReflectUtils.forName("{nms}.Vec3D");
            MovingObjectPosition = NMSReflectUtils.forName("{nms}.MovingObjectPosition");
            MovingObjectPositionEntity = version < 11400 ? null : NMSReflectUtils.forName("{nms}.MovingObjectPositionEntity");
            MovingObjectPositionBlock = version < 11400 ? null : NMSReflectUtils.forName("{nms}.MovingObjectPositionBlock");
            RayTrace = version < 11400 ? null : NMSReflectUtils.forName("{nms}.RayTrace");
            BlockCollisionOption = version < 11400 ? null : NMSReflectUtils.forName("{nms}.RayTrace$BlockCollisionOption");
            FluidCollisionOption = version < 11300 ? null : version < 11400 ? NMSReflectUtils.forName("{nms}.FluidCollisionOption") : NMSReflectUtils.forName("{nms}.RayTrace$FluidCollisionOption");

            EnumDirection = version < 10800 ? null : NMSReflectUtils.forName("{nms}.EnumDirection");
            EnumMovingObjectType = NMSReflectUtils.forName("{nms}.MovingObjectPosition$EnumMovingObjectType", "{nms}.EnumMovingObjectType");
            AxisAlignedBB = NMSReflectUtils.forName("{nms}.AxisAlignedBB");
//            语言
            LocaleLanguage = NMSReflectUtils.forName("{nms}.LocaleLanguage");
            DimensionManager = version < 10900 ? null : NMSReflectUtils.forName("{nms}.DimensionManager");
            ChatMessage = NMSReflectUtils.forName("{nms}.ChatMessage");


        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}
